package com.hundredapp.oa.web.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import com.hundredapp.oa.dao.SelectType;
import com.hundredapp.oa.domain.OaContract;
import com.hundredapp.oa.repository.ContractManager;
import com.hundredapp.oa.repository.StudentManager;
import com.opensymphony.xwork2.ActionSupport;

@Repository
@Scope("prototype")
public class Contract extends ActionSupport {
	@Autowired
	private ContractManager contractManager;
	
	@Autowired
	private StudentManager studentManager;
	
	private List<OaContract> root;
	
	private Integer studentid = 0;
	
	public String all() {
		String condition = SelectType.SELECT_ALL;
		//condition += " and student_id is null";
		root = contractManager.findNonUse(condition);
		List<OaContract> cs = new ArrayList<OaContract>(0);
		if(studentid != 0) {
			cs = studentManager.findById(studentid).getOaContracts();
		}
		for(OaContract each : cs) {
			root.add(each);
		}
		return SUCCESS;
	}

	public void setContractManager(ContractManager contractManager) {
		this.contractManager = contractManager;
	}

	public List<OaContract> getRoot() {
		return root;
	}

	public void setStudentManager(StudentManager studentManager) {
		this.studentManager = studentManager;
	}

	public Integer getStudentid() {
		return studentid;
	}

	public void setStudentid(Integer studentid) {
		this.studentid = studentid;
	}


}
